package com.example.controller;

import com.example.common.Result;
import com.example.pojo.entity.Order;
import com.example.pojo.entity.WriteOff;
import com.example.service.WriteOffService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/writeOff")
public class WriteOffController {

    @Resource
    private WriteOffService writeOffService;

    @PostMapping("/add")
    public Result add(@RequestBody WriteOff writeOff) {
        writeOffService.insert(writeOff);
        return Result.success();
    }

   @PutMapping("/update")
    public Result update(@RequestBody WriteOff writeOff) {
        writeOffService.updateWriteOff(writeOff);
        return Result.success();
    }

    @GetMapping("/selectByPage")
    public Result selectByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "") String name,
            @RequestParam(defaultValue = "") String phone) {
        PageInfo<Order> pageInfo = writeOffService.selectByPage(pageNum, pageSize, name, phone);
        return Result.success(pageInfo);
    }
}
